<template>
    <view class="container">
      <!-- 新增二维码展示区域 -->
      <view v-if="orderData.status === 'PENDING_SETTLE' || orderData.status === 'PENDING_CONFIRM'" class="qrcode-section">
        <image 
          show-menu-by-longpress="{{true}}"
          :src="'https://zhihu.xmjsy.com' + orderData.qrCode"
        
          alt="订单二维码"
        />
        <text class="qrcode-tip">护工签到请出示此码</text>
      </view>

      <!-- 新增联系客服按钮 -->
      <view class="contact-button" @click="goToCustomerService">
        <text>联系客服</text>
      </view>

      <!-- 预约信息 -->
      <view class="section">
        <text class="section-title">预约信息</text>
        <view class="detail-item">
          <text class="label">服务名称：</text>
          <text class="value">{{ orderData.serviceName }}</text>
        </view>
        <view class="detail-item">
          <text class="label">服务方式：</text>
          <text class="value">{{ orderData.serviceMethod }}</text>
        </view>
        <view class="detail-item">
          <text class="label">护工姓名：</text>
          <text class="value">{{ orderData.caregiverName }}</text>
        </view>
        <view class="detail-item">
          <text class="label">预约日期：</text>
          <text class="value">{{ formatDate(orderData.appointmentStartDate) }}</text>
        </view>
        <view class="detail-item">
          <text class="label">预约时间：</text>
          <text class="value">{{ orderData.serviceStartTime }} - {{ orderData.serviceEndTime }}</text>
        </view>
        <view class="detail-item">
          <text class="label">医院名称：</text>
          <text class="value">{{ orderData.hospitalName }}</text>
        </view>
        <view class="detail-item">
          <text class="label">科室名称：</text>
          <text class="value">{{ orderData.departmentName }}</text>
        </view>
        <view class="detail-item">
          <text class="label">床号：</text>
          <text class="value">{{ orderData.bedNumber }}</text>
        </view>
      </view>

      <!-- 订单费用 -->
      <view class="section">
        <text class="section-title">订单费用</text>
        <view class="detail-item">
          <text class="label">订单金额：</text>
          <text class="value amount">¥{{ orderData.settlementAmount }}</text>
        </view>
        <view class="detail-item">
          <text class="label">结算时间：</text>
          <text class="value">{{ formatDateTime(orderData.settlementTime) }}</text>
        </view>
      </view>

      <!-- 订单信息 -->
      <view class="section">
        <text class="section-title">订单信息</text>
        <view class="detail-item">
          <text class="label">订单编号：</text>
          <text class="value">{{ orderData.dispatchNumber }}</text>
        </view>
        <view class="detail-item">
          <text class="label">订单状态：</text>
          <uni-tag :text="getStatusText(orderData.status)" :type="getStatusType(orderData.status)" />
        </view>
        <view class="detail-item">
          <text class="label">创建时间：</text>
          <text class="value">{{ formatDateTime(orderData.createTime) }}</text>
        </view>
        <!-- <view class="detail-item">
          <text class="label">更新时间：</text>
          <text class="value">{{ formatDateTime(orderData.updateTime) }}</text>
        </view> -->
      </view>
       <view v-if="noticeContent" class="notice-bar">
      <text>{{ noticeContent }}</text>
    </view>
    </view>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  import { onLoad } from '@dcloudio/uni-app';
  
  const orderData = ref({});
  
  
  onLoad((options) => {
    if (options.data) {
      orderData.value = JSON.parse(decodeURIComponent(options.data));
    }
  });
  
  const formatDate = (dateString) => {
    if (!dateString) return '';
    return new Date(dateString).toLocaleDateString('zh-CN');
  };
  
  const formatDateTime = (dateString) => {
    if (!dateString) return '';
    return new Date(dateString).toLocaleString('zh-CN');
  };
  
  const getStatusText = (status) => {
    const statusMap = {
      'PENDING_SETTLE': '待结算',
      'IN_SERVICE': '服务中',
      'SETTLED': '已结算'
    };
    return statusMap[status] || '未知状态';
  };
  
  const getStatusType = (status) => {
    const typeMap = {
      'PENDING_SETTLE': 'warning',
      'IN_SERVICE': 'primary',
      'SETTLED': 'success'
    };
    return typeMap[status] || 'default';
  };
  
  // 跳转到联系客服页面
  const goToCustomerService = () => {
    uni.navigateTo({
      url: '/pages/customer-platform/my/customerService'
    });
  };
  </script>
  
  <style scoped lang="scss">
  .container {
    padding: 20rpx;
    background-color: #f5f5f5;
    min-height: 100vh;
  }
  
  // 新增联系客服按钮样式
  .contact-button {
    background-color: #ffcc00;
    color: #fff;
    padding: 16rpx 32rpx;
    border-radius: 8rpx;
    font-size: 28rpx;
    font-weight: bold;
    text-align: center;
    margin: 20rpx;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
    cursor: pointer;
  }
  
  .section {
    background: white;
    border-radius: 12rpx;
    padding: 24rpx;
    margin: 20rpx;
    box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
  
    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 20rpx;
      display: block;
    }
  }
  
  .detail-item {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    padding: 12rpx 0;
    border-bottom: 1rpx solid #eee;
  
    .label {
      width: 160rpx;
      font-size: 28rpx;
      color: #666;
    }
  
    .value {
      flex: 1;
      font-size: 28rpx;
      color: #333;
  
      &.amount {
        color: #ff9900;
        font-weight: bold;
      }
    }
  }

  // 修改二维码样式
  .qrcode-section {
    background: white;
    border-radius: 12rpx;
    padding: 24rpx;
    margin: 20rpx;
    box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
    text-align: center;

    .qrcode-image {
      width: 300rpx;
      height: 300rpx;
      margin-bottom: 16rpx;
    }

    .qrcode-tip {
      font-size: 24rpx;
      color: #666;
      margin-top: 8rpx;
    }
  }
  .notice-bar {
  background-color: #fffbe6;
  padding: 16rpx;
  border-radius: 8rpx;
  margin-bottom: 24rpx;
  display: flex;
  align-items: center;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);

  .notice-content {
    font-size: 28rpx;
    color: #333;
    flex: 1;
  }
}
  </style>